package com.diploma.project.aiqiyi.aspect;

import com.diploma.project.aiqiyi.CommonResponse;
import com.diploma.project.aiqiyi.dto.VideoDetailDto;
import com.diploma.project.aiqiyi.service.VideoService;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Slf4j
@Aspect
@Order(6)
@Component
public class VideoHistoryAspect {

    @Autowired
    private VideoService videoService;

    @Pointcut("execution(* com.diploma.project.aiqiyi..controller.VideoController.getOne(..))")
    public void insert() {

    }

    @AfterReturning(pointcut="insert()", returning = "rst")
    public void processHandler(CommonResponse<VideoDetailDto> rst) throws Throwable {
        try {
            VideoDetailDto dto = rst.getData();
            // XXXWQ: 此处建议使用多线程方式进行耗时操作，用户信息当做参数传入
            videoService.saveUserVideo(dto.getId(), 1,null);
        } catch (Exception e) {
            throw e;
        }
    }
}
